package com.example.serviceconsumer;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author sidian
 * @date 2020/11/14 15:31
 */
@Slf4j
@RestController
@RefreshScope
public class TestController {
    @Resource
    ApiController apiController;
    @Value("${my.a}")
    int a;

    public TestController() {
        log.info("constructor");
    }

    @PostConstruct
    public void init() {
        log.info("init");
    }

    @SentinelResource("hello")
    @GetMapping("/user")
    public String getUser() {
        return apiController.getUser();
    }

    @GetMapping("/config")
    public String getConfig() {
        return String.format("a:%d", a);
    }
}
